package eightDataType.mStr;

import beeboxes.TextsUtils;
import entity.Person;

/**
 * @author Ajie
 * @date 2023/3/29
 * @function 结论：kotlin or java
 *
 * sb.append("");sb.append("");sb.append("");
 * sb.toString()=="" //true
 *
 * sb.append(null);sb.append(null); >>>sb.toString(): nullnull
 * "null".equals(sb0.toString()) == true
 *
 *" ".trim().length()==0,,,  0! 0! 无论夹击与否
 *" ".trim().equals("") == true
 */
public class StringBuilderAppendDemo {

    public static void main(String[] args) {

        System.out.println("StringBuilderAppendDemo:main:"+checkMd5Params(new Integer(10)));

        System.out.println("StringBuilderAppendDemo:main:noSpace.trim().length():"+(" ".trim().length()));
        System.out.println("StringBuilderAppendDemo:main:noSpace.trim().equals(\"\"):"+(" ".trim().equals("")));

        StringBuilder sb01 = new StringBuilder();
        sb01.append("");
        System.out.println("StringBuilderAppendDemo:main:"+ (sb01.toString()==null)+","+(sb01.toString().length()<1));


        StringBuilder sb0 = new StringBuilder();
        Person a = null;
        sb0.append(a);
        sb0.append(a);
        System.out.println("StringBuilderAppendDemo:main:null:   "+"null".equals(sb0.toString()) +" toString:"+sb0.toString());

        StringBuilder sb = new StringBuilder();
        sb.append(1);
        sb.append("");
        sb.append("");
        sb.append("");
        sb.append(2);

        StringBuilder sb2 = new StringBuilder();
        sb2.append(1);
        sb2.append("");
        sb2.append(2);

        System.out.println(":main: "+sb.toString());
        System.out.println(":main: "+sb2.toString());
        System.out.println(":main: ${sb.toString()==sb2.toString()}:"+(sb.toString().equals(sb2.toString())));


        // 创建一个 StringBuffer 对象用于缓存
        StringBuffer buffer = new StringBuffer();

        // 假设这是一个不断产生的字符串数据
        for (int i = 0; i < 20; i++) {
            buffer.append("这是第 " + i + " 次写入的数据。\n");
        }

        // 打印缓存的内容
        System.out.println(buffer.toString());
        // 清理缓存的内容方法二：删除所有字符
        buffer.delete(0, buffer.length());
        // 打印清理后的内容，应该是空的
        System.out.println("清理后的内容: '" + buffer.toString() + "'");
    }


    public static String checkMd5Params(Object obj){
        if (obj == null) return "";

        if (obj instanceof String){
            String str = (String) obj;
            if ("null".equals(str) || str.length()<1){
                return "";
            }
            return str.trim();//"  ">>""
        }
        return String.valueOf(obj);

    }
}
